package com.zito.health.service.impl;

import com.zito.health.dto.LaboratoryChangeDto;
import com.zito.health.dto.LaboratoryCheckDto;
import com.zito.health.dto.LaboratoryCheckPrintDto;
import com.zito.health.entity.Laboratory;
import com.zito.health.entity.LaboratoryChange;
import com.zito.health.entity.LaboratoryCheck;
import com.zito.health.mapper.LaboratoryCheckMapper;
import com.zito.health.mapper.LaboratoryMapper;
import com.zito.health.service.LaboratoryCheckService;
import com.zito.health.vo.LaboratoryChangeVo;
import com.zito.health.vo.LaboratoryCheckVo;
import com.zito.health.vo.LaboratoryInfoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @description:
 * @author: sam
 * @time: 2020/02/28 15:33
 *
 */
@Service
public class LaboratoryCheckServiceImpl implements LaboratoryCheckService {

    @Autowired
    private LaboratoryMapper laboratoryMapper;
    @Autowired
    private LaboratoryCheckMapper laboratoryCheckMapper;

    @Override
    @Transactional
    public LaboratoryCheck save(LaboratoryCheck object) {
        int res = laboratoryCheckMapper.insertSelective(object);
        Laboratory laboratory = new Laboratory();
        laboratory.setStates(6);//6.变更中
        laboratory.setId(object.getLaboratoryId());
        laboratoryMapper.updateByPrimaryKeySelective(laboratory);
        return object;
    }


    @Override
    public void update(LaboratoryCheck object) {
        laboratoryCheckMapper.updateByPrimaryKeySelective(object);
    }

    @Override
    public List<LaboratoryCheckDto> queryLaboratoryCheck(LaboratoryCheckDto object) {
        return laboratoryCheckMapper.queryLaboratoryCheck(object);
    }

    @Override
    @Transactional
    public int deleteById(Integer id,Integer laboratoryId ) {
        //改变其实验室的状态
        Laboratory laboratory = new Laboratory();
        laboratory.setId(laboratoryId);
        laboratory.setStates(4);//市审核通过
        laboratoryMapper.updateByPrimaryKeySelective(laboratory);

        //删除变更
        laboratoryCheckMapper.deleteByPrimaryKey(id);

        return 0;
    }

    @Override
    public LaboratoryInfoVo getLabInfoByLabId(Integer laboratoryId) {
        LaboratoryInfoVo laboratoryInfoVo = laboratoryMapper.getLabInfoByLabId(laboratoryId);
        return laboratoryInfoVo;
    }

    @Override
    public LaboratoryCheckVo getLabInfoByLabCheckId(Integer checkId) {
        LaboratoryCheckVo laboratoryCheckVo = laboratoryCheckMapper.getLabInfoByLabCheckId(checkId);
        return laboratoryCheckVo;
    }

    @Override
    public LaboratoryCheckPrintDto print(Integer checkId) {
        return laboratoryCheckMapper.print(checkId);
    }

}
